package role

import (
	"context"

	"go-zero-mall/app/admin/cmd/api/internal/svc"
	"go-zero-mall/app/admin/cmd/api/internal/types"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type RolePageListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRolePageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RolePageListLogic {
	return &RolePageListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RolePageListLogic) RolePageList(req *types.RolePageReq) (resp *types.RolePageResp, err error) {
	var in pd.UmsRoleListReq
	err = copier.Copy(&in, req)
	if err != nil {
		return nil, err
	}
	d, err := l.svcCtx.AdminRpc.RoleList(l.ctx, &in)
	if err != nil {
		return nil, err
	}
	var list []types.Role
	err = copier.Copy(&list, d.List)
	if err != nil {
		return nil, err
	}
	return &types.RolePageResp{
		Total: d.Total,
		List:  list,
	}, err
}
